// pages/player/player.js
const app = getApp()
var utils = require('../../utils/utils.js');

Page({
  data: {
    videoCircieImageLeft: 'videoCircieImageLeft',
    timeout: [
      { text: "不开启" },
      { text: "播放当前声音关闭" },
      { text: "播放2首声音关闭" },
      { text: "播放3首声音关闭" },
      { text: "播放4首声音关闭" },
      { text: "10分钟后" },
      { text: "20分钟后" },
      { text: "30分钟后" },
    ],
    activeIndex: 0,
  },

  onLoad: function (options) {
    var that = this;
    console.log(options.id);
    var url = 'http://127.0.0.1:8000/player/' + options.id + '/';
    utils.myRequest({
      url: url,
      methods: 'GET',
      success: function (res) {
        console.log(res);//打印出返回的数据
        that.setData({
          result: res.data
        })
      },
      fail:function(){

      }
    })
    utils.myRequest({
      url: 'http://127.0.0.1:8000/stock/' + options.id + '/',
      methods: 'PUT',
      success: function (res) {
        console.log(res);//打印出返回的数据
      },
      fail: function () {

      }
    })
  },

  openSwitch: function (options) {
    var that = this;
    that.setData({
      show: true
    })
  },
  close: function (options) {
    var that = this;
    that.setData({
      show: false
    })
  },
  chooseTimeOut: function (e) {
    var that = this;
    console.log(e)
    that.setData({
      activeIndex: e.currentTarget.dataset.activeindex
    })
  },

  // 播放进度条
  MusicStart: function (e) {
    var progress = parseInt((e.detail.currentTime / e.detail.duration) * 100)
    var that = this
    that.setData({
      progress: progress
    })
    console.log('音乐播放进度为' + progress + '%')
  },

})
